using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarCapacityExcessClaimDB
    {
        public CarCapacityExcessClaimDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarCapacityExcessClaim carclaimexcess)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCapacityExcessClaimInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarCapacityExcessClaimId", carclaimexcess.ProviderCarCapacityExcessClaimId);
            _sPara.Add("@ProviderCompanyId", carclaimexcess.ProviderCompanyId);
            _sPara.Add("@ProviderCarClaimExpId", carclaimexcess.ProviderCarClaimExpId);
            _sPara.Add("@FromCC", carclaimexcess.FromCC);
            _sPara.Add("@ToCC", carclaimexcess.ToCC);
            _sPara.Add("@ExcessAmount", carclaimexcess.ExcessAmount);
            _sPara.Add("@RefCEUserId", carclaimexcess.RefCEUserId);
            _sPara.Add("@Status", carclaimexcess.Status);
            _sPara.Add("@Finfo1", carclaimexcess.FInfo1);
            _sPara.Add("@Dinfo1", carclaimexcess.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 InsertEtiqa(CarCapacityExcessClaim carclaimexcess)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCapacityExcessClaimInsertUpdateSingleItemEtiqa]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarCapacityExcessClaimId", carclaimexcess.ProviderCarCapacityExcessClaimId);
            _sPara.Add("@ProviderCompanyId", carclaimexcess.ProviderCompanyId);
            _sPara.Add("@ProviderCarClaimExpId", carclaimexcess.ProviderCarClaimExpId);
            _sPara.Add("@FromCC", carclaimexcess.FromCC);
            _sPara.Add("@ToCC", carclaimexcess.ToCC);
            _sPara.Add("@ExcessAmount", carclaimexcess.ExcessAmount);
            _sPara.Add("@RefCEUserId", carclaimexcess.RefCEUserId);
            _sPara.Add("@Status", carclaimexcess.Status);
            _sPara.Add("@Info1", carclaimexcess.info1);
            _sPara.Add("@Ninfo1", carclaimexcess.NInfo1);
            _sPara.Add("@Ninfo2", carclaimexcess.NInfo2);
            _sPara.Add("@Finfo1", carclaimexcess.FInfo1);
            _sPara.Add("@Dinfo1", carclaimexcess.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete(Int64 ProviderCarCapacityExcessClaimId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCapacityExcessClaimDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarCapacityExcessClaimId", ProviderCarCapacityExcessClaimId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

        public CarCapacityExcessClaimList GetProviderCarClaimExcessPointList(Int64 ProviderCompanyId)
        {
            CarCapacityExcessClaimList _capacitylist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _capacitylist = new CarCapacityExcessClaimList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarCapacityExcessClaim _capacity = new CarCapacityExcessClaim();
                        _capacity = FillDataRecord(_dt, i);
                        _capacitylist.Add(_capacity);
                    }
                }
            }
            return _capacitylist;
        }


        public CarCapacityExcessClaim GetProviderCarCapacityExcessClaim(Int64 ProviderCompanyId, Int64 ProviderCarClaimExpId, int FromCC, int ToCC)
        {
            CarCapacityExcessClaim _carcapacity = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderCarClaimExpId", ProviderCarClaimExpId);
            _spara.Add("@FromCC", FromCC);
            _spara.Add("@ToCC", ToCC);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carcapacity = new CarCapacityExcessClaim();
                    _carcapacity = FillDataRecord(_dt, 0);
                }
            }
            return _carcapacity;
        }

        public bool CheckProviderCarCapacityExcessClaimDuplicate(Int64 CurrentProviderCarCapacityExcessClaimId, Int64 ProviderCompanyId, Int64 ProviderCarClaimExpId, int FromCC, int ToCC)
        {
            bool _retValue = false;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimDuplicateSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarCapacityExcessClaimId", CurrentProviderCarCapacityExcessClaimId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderCarClaimExpId", ProviderCarClaimExpId);
            _spara.Add("@FromCC", FromCC);
            _spara.Add("@ToCC", ToCC);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _retValue = true;
                }
            }
            return _retValue;
        }

        public bool CheckProviderCarCapacityExcessClaimDuplicateEtiqa(Int64 CurrentProviderCarCapacityExcessClaimId, Int64 ProviderCompanyId, Int64 ProviderCarClaimExpId, int FromCC, int ToCC, string Info1, int FromClaim, int ToClaim)
        {
            bool _retValue = false;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimDuplicateSelectSingleItemEtiqa";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarCapacityExcessClaimId", CurrentProviderCarCapacityExcessClaimId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderCarClaimExpId", ProviderCarClaimExpId);
            _spara.Add("@FromCC", FromCC);
            _spara.Add("@ToCC", ToCC);
            _spara.Add("@Info1", Info1);
            _spara.Add("@Ninfo1", FromClaim);
            _spara.Add("@Ninfo2", ToClaim);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _retValue = true;
                }
            }
            return _retValue;
        }

        public CarCapacityExcessClaim GetProviderCarCapacityExcessClaim(Int64 ProviderCarCapacityExcessClaimId)
        {
            CarCapacityExcessClaim _carexcessclaim = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarCapacityExcessClaimId", ProviderCarCapacityExcessClaimId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carexcessclaim = new CarCapacityExcessClaim();
                    _carexcessclaim = FillDataRecord(_dt, 0);
                }
            }
            return _carexcessclaim;
        }

        public CarCapacityExcessClaim GetProviderCarCapacityExcessClaimEtiqa(Int64 ProviderCompanyId, Int64 ProviderCarClaimExpId, int FromCC, int ToCC, string info1, int FromClaim, int ToClaim)
        {
            CarCapacityExcessClaim _carcapacity = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimSelectSingleItemEtiqa";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderCarClaimExpId", ProviderCarClaimExpId);
            _spara.Add("@FromCC", FromCC);
            _spara.Add("@ToCC", ToCC);
            _spara.Add("@Info1", info1);
            _spara.Add("@Ninfo1", FromClaim);
            _spara.Add("@Ninfo2", ToClaim);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carcapacity = new CarCapacityExcessClaim();
                    _carcapacity = FillDataRecordEtiqa(_dt, 0);
                }
            }
            return _carcapacity;
        }

        public CarCapacityExcessClaim GetProviderCarCapacityExcessClaimEtiqa(Int64 ProviderCompanyId, string Info1, int CECarId, int RefCEUserId)
        {
            CarCapacityExcessClaim _carcapacity = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacityExcessClaimSelectEtiqa";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@Info1", Info1);            
            _spara.Add("@CECarId", CECarId);        
            _spara.Add("@RefCEUserId", RefCEUserId);
          
            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carcapacity = new CarCapacityExcessClaim();
                    _carcapacity = FillDataRecordEtiqa(_dt, 0);
                }
            }
            return _carcapacity;
        }

        private CarCapacityExcessClaim FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarCapacityExcessClaim myCarExcessClaim = new CarCapacityExcessClaim();
            myCarExcessClaim.ProviderCarCapacityExcessClaimId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarCapacityExcessClaimId"].ToString());
            myCarExcessClaim.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarExcessClaim.ProviderCarClaimExpId = Convert.ToInt32(myDataTable.Rows[RowId]["ProviderCarClaimExpId"].ToString());
            myCarExcessClaim.FromCC = Convert.ToInt32(myDataTable.Rows[RowId]["FromCC"].ToString());
            myCarExcessClaim.ToCC = Convert.ToInt32(myDataTable.Rows[RowId]["ToCC"].ToString());
            myCarExcessClaim.ExcessAmount = Convert.ToSingle(myDataTable.Rows[RowId]["ExcessAmount"].ToString());
            myCarExcessClaim.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarExcessClaim.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarExcessClaim.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarExcessClaim.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarExcessClaim.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarExcessClaim;

        }

        private CarCapacityExcessClaim FillDataRecordEtiqa(DataTable myDataTable, int RowId)
        {
            CarCapacityExcessClaim myCarExcessClaim = new CarCapacityExcessClaim();
            myCarExcessClaim.ProviderCarCapacityExcessClaimId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarCapacityExcessClaimId"].ToString());
            myCarExcessClaim.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarExcessClaim.ProviderCarClaimExpId = Convert.ToInt32(myDataTable.Rows[RowId]["ProviderCarClaimExpId"].ToString());
            myCarExcessClaim.FromCC = Convert.ToInt32(myDataTable.Rows[RowId]["FromCC"].ToString());
            myCarExcessClaim.ToCC = Convert.ToInt32(myDataTable.Rows[RowId]["ToCC"].ToString());
            myCarExcessClaim.ExcessAmount = Convert.ToSingle(myDataTable.Rows[RowId]["ExcessAmount"].ToString());
            myCarExcessClaim.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarExcessClaim.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarExcessClaim.info1 = myDataTable.Rows[RowId]["Info1"].ToString();
            myCarExcessClaim.NInfo1 = Convert.ToInt32(myDataTable.Rows[RowId]["NInfo1"].ToString());
            myCarExcessClaim.NInfo2 = Convert.ToInt32(myDataTable.Rows[RowId]["NInfo2"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarExcessClaim.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarExcessClaim.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarExcessClaim.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarExcessClaim;

        }
        
    }
}